package br.com.truta.bd;

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class ConnectionFactory {

	private ConnectionFactory() {
		super();
	}
	
	/**
	 * @return Connection para o banco local.
	 * @throws Exception
	 */
	public static Connection getLocalMySQLConnection() throws Exception {
		DataSource dataSource = getDataSource("jdbc/LocalMySQL");
		return dataSource.getConnection();
	}

	private static DataSource getDataSource(String name) throws Exception {
		Context initContext = new InitialContext();
		DataSource ds = (DataSource) initContext.lookup("java:/comp/env/" + name);
		return ds;
	}

}
